package com.xiaozhen.cmdb.controller;

import com.xiaozhen.cmdb.service.CmdbModelAttributeService;
import com.xiaozhen.security.controller.BaseController;
import com.xiaozhen.common.core.domain.AjaxResult;
import com.xiaozhen.common.core.domain.cmdb.CmdbModelAttribute;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * HISTORY
 *
 * @author zhenweisheng
 * @date 2021/9/9 8:12
 * @description:
 */
@Api(tags = "Cmdb模型属性接口")
@RestController
@RequestMapping("cmdbModelAttribute")
public class CmdbModelAttributeController extends BaseController {

    @Autowired
    private CmdbModelAttributeService cmdbModelAttributeService;

    @ApiOperation("添加或添加协议属性信息")
    @PostMapping("/addCmdbModelAttributes")
    public AjaxResult addCmdbModelAttributes(@Validated @RequestBody List<CmdbModelAttribute> list) {
        Long currentUserId = getCurrentUserId();
        return toAjax(cmdbModelAttributeService.insertCmdbModelAttributeList(list,currentUserId));
    }


    @ApiOperation("查询协议属性信息")
    @GetMapping("/selectCmdbModelAttributesByModelId/{modelId}")
    public AjaxResult selectCmdbModelAttributesByModelId(@PathVariable Long modelId) {
        Long currentUserId = getCurrentUserId();
        List<CmdbModelAttribute> cmdbModelAttributes = cmdbModelAttributeService.selectCmdbModelAttributesByModelId(modelId, currentUserId);
        return AjaxResult.success(cmdbModelAttributes);
    }
}
